home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2008 December / PC_Format_122008.iso / Multimedia / MediaPortal 0.2.3.0 / MediaPortal_0.2.3.0_Setup.exe / scripts / imdb / port_hu.csscript < prev    next >
Text File  |  2007-09-02  |  8KB  |  263 lines

  1. //css_reference "core.dll";
  2. //css_reference "Databases.dll";
  3. //css_reference "utils.dll";
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using System.IO;
  13. using System.Net;
  14. using System.Collections;
  15. using System.Web;
  16. using System.Text.RegularExpressions;
  17. using MediaPortal.Util;
  18.  
  19. // change to Grabber, this for avoid to load by mediaportal
  20. class Grabber : MediaPortal.Video.Database.IIMDBScriptGrabber
  21. {
  22.   public Grabber()
  23.     {
  24.     }
  25.  
  26.   void MediaPortal.Video.Database.IIMDBScriptGrabber.FindFilm(string strSearch, int iLimit, ArrayList elements)
  27.   {
  28.     string strURL = "http://www.port.hu/pls/ci/cinema.film_list?i_film_title="+strSearch+"&i_city_id=3372&i_county_id=-1";
  29.     string absoluteUri;
  30.     int iCount = 0;
  31.     try
  32.     {
  33.       string strBody = GetPage(strURL, "ISO-8859-1", out absoluteUri);
  34.       string strurl = string.Empty;
  35.       string strtitle = string.Empty;
  36.       MediaPortal.Util.HTMLParser parser = new MediaPortal.Util.HTMLParser(strBody);
  37.       while ((parser.Position < strBody.Length) && (iCount < iLimit))
  38.       {
  39.         if (parser.skipToEndOfNoCase("\"btxt\"><a href=\"")&&
  40.           parser.extractTo("\"", ref strurl))
  41.         {
  42.           if (parser.skipToEndOfNoCase("\"_top\">") &&
  43.               parser.extractTo("</span>", ref strtitle))
  44.           {
  45.             strurl = "http://www.port.hu" + strurl;
  46.             strtitle = strtitle.Replace("</a>", " ");
  47.             MediaPortal.Video.Database.IMDB.IMDBUrl url = new MediaPortal.Video.Database.IMDB.IMDBUrl(strurl, strtitle + " (port_hu)", "port_hu");
  48.             elements.Add(url);
  49.           }
  50.         }
  51.         iCount++;
  52.       }
  53.     }
  54.     catch (Exception ex)
  55.     {
  56.       MediaPortal.GUI.Library.Log.Error("exception for port_hu lookup of {0} err:{1} stack:{2}", strURL, ex.Message, ex.StackTrace);
  57.     }
  58.   }
  59.  
  60.  
  61.   bool MediaPortal.Video.Database.IIMDBScriptGrabber.GetDetails(MediaPortal.Video.Database.IMDB.IMDBUrl url, ref MediaPortal.Video.Database.IMDBMovie movieDetails)
  62.   {
  63.     movieDetails.Reset();
  64.     movieDetails.Database = "port_hu";
  65.     string strAbsURL;
  66.     url.URL = url.URL.Replace("&", "&");
  67.     string strBody = GetPage(url.URL, "ISO-8859-1", out strAbsURL);
  68.     HTMLUtil htmlUtil = new HTMLUtil();
  69.     if (strBody == null || strBody.Length == 0)
  70.       return false;
  71.     MediaPortal.Util.HTMLParser parser = new MediaPortal.Util.HTMLParser(strBody);
  72.     if (parser.skipToEndOfNoCase("blackbigtitle\">"))
  73.     {
  74.  
  75.       string strTitle = String.Empty;
  76.       string strYear = String.Empty;
  77.       string runtime = String.Empty;
  78.       string strDirector = String.Empty;
  79.       string strWriting = String.Empty;
  80.       string strCast = String.Empty;
  81.       string strGenre = String.Empty;
  82.       string strPlot = String.Empty;
  83.       string strNumber = String.Empty;
  84.       string strThumb = String.Empty;
  85.       string strRating = String.Empty;
  86.       string strVotes = String.Empty;
  87.       string strMpaa = String.Empty;
  88.       string strother = String.Empty;
  89.       if (parser.extractTo("</span>", ref strTitle))
  90.         movieDetails.Title = strTitle;
  91.       if (parser.skipToEndOfNoCase("<span class=\"txt\">(") && parser.extractTo(")</center>", ref strTitle))
  92.       {
  93.         movieDetails.Title = strTitle;
  94.       }
  95.  
  96.       if (parser.skipToEndOfNoCase("\"btxt\">") && parser.extractTo(",", ref strother))
  97.       {
  98.         movieDetails.TagLine = strother;
  99.       }
  100.  
  101.       if (parser.extractTo("perc,", ref runtime))
  102.       {
  103.         try
  104.         {
  105.           movieDetails.RunTime = System.Int32.Parse(runtime.Trim());
  106.         }
  107.         catch (Exception)
  108.         {
  109.           movieDetails.RunTime =0;
  110.         }
  111.       }
  112.  
  113.       if (parser.extractTo("</span>", ref strYear))
  114.       {
  115.         try
  116.         {
  117.           movieDetails.Year = System.Int32.Parse(strYear.Trim());
  118.         }
  119.         catch (Exception)
  120.         {
  121.           movieDetails.Year = 1970;
  122.         }
  123.       }
  124.  
  125.       if (parser.skipToEndOfNoCase("<span class=\"btxt\">") && parser.extractTo("</span>", ref strMpaa))
  126.       {
  127.         movieDetails.MPARating = strMpaa;
  128.       }
  129.       
  130.       if (parser.skipToEndOfNoCase("<span class=\"btxt\">rendez") && 
  131.         parser.skipToEndOfNoCase("_top\">") && 
  132.         parser.extractTo("<br>", ref strDirector))
  133.       {
  134.         movieDetails.Director = MediaPortal.Util.HTMLParser.removeHtml(strDirector);
  135.       }
  136.  
  137.       if (parser.skipToEndOfNoCase("<span class=\"btxt\">forgat") &&
  138.         parser.skipToEndOfNoCase("_top\">") &&
  139.         parser.extractTo("<br>", ref strWriting))
  140.       {
  141.         movieDetails.WritingCredits = MediaPortal.Util.HTMLParser.removeHtml(strWriting);
  142.       }
  143.  
  144.       if (parser.skipToEndOfNoCase("<br><P><b>szerepl") &&
  145.         parser.skipToEndOfNoCase("_top\">") &&
  146.         parser.extractTo("</span>", ref strCast))
  147.       {
  148.         movieDetails.Cast = MediaPortal.Util.HTMLParser.removeHtml(strCast).Replace("(", " as ").Replace(")", "");
  149.       }
  150.  
  151.       if (parser.skipToEndOfNoCase("<table") &&
  152.         parser.skipToEndOfNoCase("<div class=\"separator\">") &&
  153.         parser.skipToEndOfNoCase("<span class=\"txt\">") &&
  154.         parser.extractTo("</span>", ref strPlot))
  155.       {
  156.         movieDetails.Plot = htmlUtil.ConvertHTMLToAnsi(strPlot.Replace("<BR>", Environment.NewLine));
  157.       }
  158.       movieDetails.Database = "port_hu";
  159.       return true;
  160.     }
  161.     else
  162.       return false;
  163.     // preces the web page defined by the url
  164.     // ................
  165.     // ................
  166.     // then fill the database
  167.     // movieDetails.Year
  168.     // movieDetails.Genre 
  169.     // movieDetails.Votes
  170.     // movieDetails.Top250
  171.     // movieDetails.TagLine
  172.     // movieDetails.PlotOutline
  173.     // movieDetails.ThumbURL
  174.     // movieDetails.Plot
  175.     // movieDetails.Cast
  176.     // movieDetails.RunTime = ....
  177.     // movieDetails.MPARating = ......
  178.  
  179.     // found some information 
  180.     //return true;
  181.     // else
  182.   }
  183.  
  184.   string MediaPortal.Video.Database.IIMDBScriptGrabber.GetName()
  185.   {
  186.     return "Port.hu grabber ";
  187.   }
  188.  
  189.   string MediaPortal.Video.Database.IIMDBScriptGrabber.GetLanguage()
  190.   {
  191.     return "HU";
  192.   }
  193.  
  194.   // a general procedure to get a web page 
  195.   // use like :
  196.   //    string absoluteUri;
  197.   //    string strURL = "http://us.imdb.com/Tsearch?title=" + strSearch;
  198.   //    string strBody = GetPage(strURL, "utf-8", out absoluteUri);
  199.  
  200.   private string GetPage(string strURL, string strEncode, out string absoluteUri)
  201.   {
  202.     string strBody = "";
  203.     absoluteUri = String.Empty;
  204.     Stream ReceiveStream = null;
  205.     StreamReader sr = null;
  206.     WebResponse result = null;
  207.     try
  208.     {
  209.       // Make the Webrequest
  210.       //Log.Info("IMDB: get page:{0}", strURL);
  211.       WebRequest req = WebRequest.Create(strURL);
  212.  
  213.       result = req.GetResponse();
  214.       ReceiveStream = result.GetResponseStream();
  215.  
  216.       // Encoding: depends on selected page
  217.       Encoding encode = System.Text.Encoding.GetEncoding(strEncode);
  218.       sr = new StreamReader(ReceiveStream, encode);
  219.       strBody = sr.ReadToEnd();
  220.  
  221.       absoluteUri = result.ResponseUri.AbsoluteUri;
  222.     }
  223.     catch (Exception)
  224.     {
  225.       //Log.Error("Error retreiving WebPage: {0} Encoding:{1} err:{2} stack:{3}", strURL, strEncode, ex.Message, ex.StackTrace);
  226.     }
  227.     finally
  228.     {
  229.       if (sr != null)
  230.       {
  231.         try
  232.         {
  233.           sr.Close();
  234.         }
  235.         catch (Exception)
  236.         {
  237.         }
  238.       }
  239.       if (ReceiveStream != null)
  240.       {
  241.         try
  242.         {
  243.           ReceiveStream.Close();
  244.         }
  245.         catch (Exception)
  246.         {
  247.         }
  248.       }
  249.       if (result != null)
  250.       {
  251.         try
  252.         {
  253.           result.Close();
  254.         }
  255.         catch (Exception)
  256.         {
  257.         }
  258.       }
  259.     }
  260.     return strBody;
  261.   } // END GetPage()
  262.  
  263. }